<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Select Button</title>
    <style>
        /* 按钮容器样式 */
        .button-container {
            position: relative;
            display: inline-block;
        }

        /* 按钮样式 */
        .select-button {
            padding: 10px 20px;
            border: 1px solid #ccc;
            background-color: #fff;
            cursor: pointer;
            display: flex;
            align-items: center;
        }

        /* 箭头样式 */
        .arrow {
            margin-left: 5px;
            border: solid black;
            border-width: 0 2px 2px 0;
            display: inline-block;
            padding: 3px;
            transform: rotate(45deg);
            -webkit-transform: rotate(45deg);
            cursor: pointer;
        }

        /* 下拉菜单样式 */
        .dropdown-menu {
            display: none;
            position: absolute;
            background-color: #f9f9f9;
            min-width: 160px;
            box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
            z-index: 1;
        }

        /* 下拉菜单项样式 */
        .dropdown-menu a {
            color: black;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
        }

        /* 下拉菜单项悬停样式 */
        .dropdown-menu a:hover {
            background-color: #f1f1f1;
        }
    </style>
</head>

<body>
    <!-- 按钮容器 -->
    <div class="button-container">
        <!-- 按钮 -->
        <button class="select-button" id="selectButton">
            <span id="buttonText">鼠标</span>
            <span class="arrow" id="arrow"></span>
        </button>
        <!-- 下拉菜单 -->
        <div class="dropdown-menu" id="dropdownMenu">
            <a href="#">选项 1</a>
            <a href="#">选项 2</a>
            <a href="#">选项 3</a>
        </div>
    </div>

    <script>
        // 获取按钮、按钮文本、箭头和下拉菜单元素
        const selectButton = document.getElementById('selectButton');
        const buttonText = document.getElementById('buttonText');
        const arrow = document.getElementById('arrow');
        const dropdownMenu = document.getElementById('dropdownMenu');

        // 给箭头添加点击事件监听器
        arrow.addEventListener('click', function (event) {
            event.stopPropagation();
            if (buttonText.textContent === '鼠标') {
                dropdownMenu.style.display = dropdownMenu.style.display === 'block' ? 'none' : 'block';
            }
        });

        // 给按钮添加点击事件监听器
        selectButton.addEventListener('click', function () {
            if (buttonText.textContent === '鼠标') {
                buttonText.textContent = '键盘';
                dropdownMenu.style.display = 'none';
            } else {
                buttonText.textContent = '鼠标';
            }
        });

        // 点击文档其他地方关闭下拉菜单
        document.addEventListener('click', function (event) {
            if (!selectButton.contains(event.target)) {
                dropdownMenu.style.display = 'none';
            }
        });
    </script>
</body>

</html>